<template>
  <view>
    <u-button type="primary" @click="toLogin">一键登录</u-button>
    <agree-protocol
      v-model:agree="agree"
      v-model:show="show"
      :type="ProtocolTypeEnum.USER"
    ></agree-protocol>
    <u-button type="primary" @click="switchType">切换验证码登录</u-button>
  </view>
</template>
<script setup lang="ts">
import agreeProtocol from "@/components/protocol/agree.vue";
import { ProtocolTypeEnum } from "@/utils";
import { ref } from "vue";
import { useUserStore } from "@/store";

const userStore = useUserStore();

const agree = ref(false);

const show = ref(false);

const toLogin = () => {
  if (!agree.value) {
    uni.showToast({
      title: "请先同意协议",
      icon: "none",
    });
  } else {
    userStore.login().then(() => {
      uni.showToast({
        title: "登录成功",
        icon: "none",
      });
    });
  }
};

const switchType = () => {
  uni.redirectTo({
    url: "/pages/login/verifyCode",
  });
};
</script>
